<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>

</head>
<body>
<div style="margin: 200px auto 0 auto;height: 60px;width: 200px;">
    <div>>> 给自己取个名字吧:</div>
    <div>
        <input id="username" name="username" type="text">
    </div>
    <div style="margin-top: 10px;"><button id="submit">开始聊天！</button></div>
</div>


<script type="text/javascript">
    $(function () {
        $('#submit').click(function () {
            var username = $("#username").val();
            $.post('/login', {username: username}, function (data) {
                if (data.code === 0) {
                    console.log('登录成功');
                    window.location.href = "/";
                } else {
                    console.log(data.message);
                }
            });
        });

        $(document).keyup(function(event){
            if(event.keyCode ===13){
                $("#submit").trigger("click");
            }
        });
    });
</script>

</body>
</html>